package com.ruoyi.common.gen.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.gen.entity.${entity};
import com.ruoyi.common.gen.service.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * ${table.comment} 前端控制器
 * @author ${author}
 * @date ${date}
 */
@RestController
@RequestMapping("/${table.entityPath}")
@Api(tags = {"${table.comment}控制器"})
public class ${table.controllerName} {

    /**
     * ${table.comment}业务接口
     */
    @Autowired
    private ${table.serviceName} baseService;

    /**
     * 描述：分页查询
     * @author ${author}
     * @date ${date}
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "分页查询")
    public R<IPage<${entity}>> pageList(@RequestBody ${entity} ${table.entityPath}) {
        IPage<${entity}> pageVo = baseService.pageList(${table.entityPath});
        return R.ok(pageVo);
    }
    
    /**
     * 描述：详情
     * @author ${author}
     * @date ${date}
     */
    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public R<${entity}> detail${entity}(@RequestBody Long id) {
        ${entity} ${table.entityPath} = baseService.detail${entity}(id);
        return R.ok(${table.entityPath});
    }    

    /**
     * 描述：保存
     * @author ${author}
     * @date ${date}
     */
    @PostMapping("/save${entity}")
    @ApiOperation(value = "保存")
    @Log(title = "${table.comment}管理", businessType = BusinessType.INSERT)
    public R<String> save${entity}(@RequestBody ${entity} ${table.entityPath}) {
        baseService.save${entity}(${table.entityPath});
        return R.ok("保存成功！");
    }

    /**
     * 描述：修改
     * @author ${author}
     * @date ${date}
     */
    @PostMapping("/update${entity}")
    @ApiOperation(value = "修改")
    @Log(title = "${table.comment}管理", businessType = BusinessType.UPDATE)
    public R<String> update${entity}(@RequestBody ${entity} ${table.entityPath}) {
        baseService.update${entity}(${table.entityPath});
        return R.ok("修改成功！");
    }

    /**
     * 描述：删除
     * @author ${author}
     * @date ${date}
     */
    @PostMapping("/delete${entity}")
    @ApiOperation(value = "删除")
    @Log(title = "${table.comment}管理", businessType = BusinessType.DELETE)
    public R<String> delete${entity}(@RequestBody List<Long> ids) {
        baseService.delete${entity}(ids);
        return R.ok("删除成功！");
    }

    /**
     * 描述：批量导出
     * @author ${author}
     * @date ${date}
     */
    @PostMapping("/exportExcel")
    @ApiOperation(value = "批量导出")
    @Log(title = "${table.comment}管理", businessType = BusinessType.EXPORT)
    public void exportExcel(HttpServletResponse response, @RequestBody ${entity} ${table.entityPath}) {
        baseService.exportExcel(response, ${table.entityPath});
    }

}
